package ie.timalb.chess.main.core.movement;

public class Location {
	int xCoordinate;
	int yCoordinate;
	
	public Location(int x, int y) {
		setXCoordinate(x);
		setYCoordinate(y);
	}
	
	public int getYCoordinate() {
		return yCoordinate;
	}

	public void setYCoordinate(int coordinate)		 
	{
		
		yCoordinate = coordinate;
	}

	public int getXCoordinate() {
		return xCoordinate;
	}

	public void setXCoordinate(int coordinate) 
	{			
		xCoordinate = coordinate;
	}
	
	@Override
	public boolean equals(Object input) {
		Location locationToCompare = (Location) input;
		if (
				(this.getXCoordinate() == locationToCompare.getXCoordinate()) &&
				(this.getYCoordinate() == locationToCompare.getYCoordinate())
			)
		{
			return true;
		}
		return false;
	}

	@Override
	public String toString() {
		return (String.valueOf(hashCode()));
	}
	
	@Override
	public int hashCode() {
		return (getXCoordinate() * 10) + getYCoordinate();
	}

	public Location getNextLocation(MovementDescriptor direction) {
		int x=getXCoordinate();
		int y=getYCoordinate();
		
		x = x + direction.getIncrementXInEachStep ();
		y = y + direction.getIncrementYInEachStep ();
		
		Location result = new Location (x,y);
		
		return result;
	}

	public Location getPreviousLocation(MovementDescriptor direction) {
		int x=getXCoordinate();
		int y=getYCoordinate();
		
		x = x - direction.getIncrementXInEachStep ();
		y = y - direction.getIncrementYInEachStep ();
		
		Location result = new Location (x,y);
		
		return result;
	}
}
